import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

const { VITE_DEPLOY_DIR, VITE_APP_API_URL } = loadEnv('production', process.cwd())
// https://vitejs.dev/config/
const { NODE_ENV } = process.env
const isDev = NODE_ENV === 'development'
export default defineConfig({
  base: isDev ? '/' : `https://website-1256754588.cos.ap-shanghai.myqcloud.com/${VITE_DEPLOY_DIR}`,
  publicDir: VITE_DEPLOY_DIR,
  plugins: [vue(), vueJsx()],
  server: {
    proxy: {
      [VITE_APP_API_URL]: {
        target: `https://www.tcyg.vip`,
        changeOrigin: true
      }
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
